﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace reactiveBT.BT.Blackboard
{
    /// <summary>
    /// 用于行为树节点间、行为树间的变量共享
    /// 难点1：如何让行为树节点和协程结合，做到单向绑定
    /// 难点2：如何让行为树节点间能通信
    /// 难点3：如何让行为树之间能通信
    /// </summary>
    public class Blackboard
    {
        /// <summary>
        /// 这里不可以只是简单的ArrayList
        /// 需要加一层封装，这种特殊的数据结构能够容纳键值对形式的元素，且不允许其他元素出现
        /// 单向绑定的含金量也会在这里体现
        /// </summary>
        private Dictionary<int, TreeValueList> borad;
        public Dictionary<int, TreeValueList> Board
        {
            get
            {
                return borad;
            }
        }


        private static Blackboard instance = null;
        public static Blackboard Instance
        {
            get
            {
                if (instance == null)
                    instance = new Blackboard();
                return instance;
            }
        }

        public Blackboard()
        {
            borad = new Dictionary<int, TreeValueList>();
        }
        public bool AddTree(int BTid)
        {
            if(borad.ContainsKey(BTid))
            {
                return false;
            }
            borad.Add(BTid, new TreeValueList());
            return true;
        }
        public bool DeleteTree(int BTid)
        {
            if(borad.ContainsKey(BTid))
            {
                borad.Remove(BTid);
                return true;
            }
            return false;
        }
    }
}
